package org.threadCase5;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;

public class RunnableDemo implements Runnable{
    public static ArrayList<Integer> prize=new ArrayList<>();
    public ArrayList<Integer> money=new ArrayList<>();
    public int totalMoney=0;
    static {
        Collections.addAll(prize,10,5,20,50,100,200,2,300,80,700);
    }
    @Override
    public void run() {
        while (true){
            synchronized (RunnableDemo.class){
                if (prize.isEmpty()){ // 使用 isEmpty() 检查列表是否为空
                    System.out.println(Thread.currentThread().getName()+" 抱歉，当前抽奖已经结束。");
                    break;
                } else {
                    Collections.shuffle(prize);
                    int award =prize.get(0);
                    System.out.println(Thread.currentThread().getName()+" 又产生了一个 "+ award +" 元大奖，现在还剩 "+(prize.size()-1)+" 个奖。");
                    prize.remove(0);
                }
            }
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
